;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Sales.GuaranteesFeeSettle", [])
        .controller("GuaranteesFeeSettleCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$timeout", "$filter", "EventBus", "Upload", "ybConfig", "UserContextService", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $timeout, $filter, EventBus, Upload, ybConfig, UserContextService) {
            $scope.activeFlag = [true, false, false, false];
            $scope.datePickerFlag = [false, false, false, false, false, false];
            $scope.subTabFlag = [true, false];
            $scope.materials = [];
            $scope.markInfo = {
                allChecked: false
            };

            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.detailPageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.orderMarkInfo = {
                allChecked: false
            };
            $scope.orderPageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 200,
                curPage: 1
            };
            $scope.submitted = false;
            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false
            };
            $scope.condition = {};
            $scope.orderCondition = {
                status: '1'
            };
            $scope.dataList = [];
            $scope.orderDataList = [];
            $scope.billDetailDataList = [];
            $scope.selectedList = [];
            $scope.detailInfo = {
                sex: 1,
                locked: 0,
                deliveryReceiptVO: {},
                billList: [],
                basicAttachmentList: []
            };
            $scope.abnormalObj = {
                headerInfo: {},
                detailList: []
            };
            $scope.innerOrderList = [];
            $scope.innerOrder = {
                item: null
            };
            $scope.dataSelected = {
                role: {},
                department: {}
            };
            $scope.inTypeList = [];
            $scope.deliveryStatues = [];
            $scope.tabFlag = {};
            $scope.stepList = {
                curStep: 0,
                list: []
            };
            $scope.showDatepicker = false;
            $scope.showDatepicker1 = false;
            $scope.packageMethodList = [];
            $scope.packageSpecListAll = [];
            $scope.packageInfo = {
                barcodeList: [],
            };

            $scope.showCommitmentTime = false;

            $scope.billTypeList = [

                {
                    code: "1",
                    name: "三包"
                }
            ];
            $scope.threeDayBillTypeList = [{
                code: "XGFT",
                name: "发货通知单"
            },
            {
                code: "XGSC",
                name: "三包出库单"
            }
            ];
            var tabFlag = {
                0: "新增",
                1: "编辑"
            };

            $scope.tableConfig = {
                scrollWidth: 1500,
                fixedWidth: 300,
                tableCol: [
                    {
                        type: "",
                        name: "结算单号",
                        dataField: "settlementNo",
                        width: 180,
                        isShow: true,
                        isFixed: false,
                        clickFn: "viewDetail"
                    },
                    {
                        type: "",
                        name: "经销商编码",
                        dataField: "agentOrgName",
                        width: 150,
                        isShow: true,
                        isFixed: false
                    },
                    {
                        type: "",
                        name: "经销商名称",
                        dataField: "settlementOrgName",
                        width: 150,
                        isShow: true,
                        isFixed: false
                    },
                    {
                        type: "",
                        name: "创建时间",
                        dataField: "createDate",
                        width: 80,
                        isShow: true,
                        isFixed: false
                    },
                    {
                        type: "",
                        name: "审核状态",
                        dataField: "auditStatusStr",
                        width: 80,
                        isShow: true,
                        isFixed: false
                    },
                    {
                        type: "",
                        name: "结算状态",
                        dataField: "checkStatusStr",
                        width: 80,
                        isShow: true,
                        isFixed: false
                    },
                    {
                        type: "",
                        name: "创建人",
                        dataField: "createName",
                        width: 100,
                        isShow: true,
                        isFixed: false
                    },
                    {
                        type: "",
                        name: "合计金额",
                        dataField: "totalPrice",
                        width: 100,
                        isShow: true,
                        isFixed: false
                    },
                    {
                        type: "",
                        name: "备注",
                        dataField: "remark",
                        width: 100,
                        isShow: true,
                        isFixed: false
                    },
                    {
                        type: "operate",
                        name: "操作",
                        dataField: "",
                        isShow: true,
                        isFixed: true,
                        width: 300,
                    }
                ]
            };

            //新增时左侧列表配置项
            $scope.addLeftTableConfig = {
                scrollWidth: 800,
                fixedWidth: 40,
                tableCol: [{
                    type: "",
                    name: "CRM单据号",
                    dataField: "crmOrder",
                    width: 100,
                    isShow: true,
                    isFixed: false
                },
                {
                    type: "",
                    name: "销售出库单号",
                    dataField: "salesOutBillNo",
                    width: 80,
                    isShow: true,
                    isFixed: false
                },
                {
                    type: "",
                    name: "收货人",
                    dataField: "consignee",
                    width: 60,
                    isShow: true,
                    isFixed: false
                },
                {
                    type: "",
                    name: "联系方式",
                    dataField: "contactPhone",
                    width: 100,
                    isShow: false,
                    isFixed: false,
                    toSort: true,
                    sortType: ''
                },
                {
                    type: "",
                    name: "收货地址",
                    dataField: "receiptAddress",
                    width: 100,
                    isShow: true,
                    isFixed: false
                },
                {
                    type: "",
                    name: "客户名称",
                    dataField: "settlementOrgName",
                    width: 80,
                    isShow: true,
                    isFixed: false
                },
                {
                    type: "",
                    name: "创建日期",
                    dataField: "createDate",
                    width: 130,
                    isShow: true,
                    isFixed: false
                }
                ]
            };


            $scope.abnormalInNewTbConf = {
                scrollWidth: 950,
                tableCol: [{
                    name: "零件编号",
                    width: 150,
                    dataField: "materialsNo",
                    input: false,
                    inputType: ""
                },
                {
                    name: "零件中文名",
                    width: 200,
                    dataField: "materialsDes",
                    input: false,
                    inputType: ""
                },
                {
                    name: "分类",
                    width: 150,
                    dataField: "materialsType",
                    input: false,
                    inputType: ""
                },
                {
                    name: "单位",
                    width: 120,
                    dataField: "unit",
                    input: false,
                    inputType: ""
                },
                {
                    name: "数量",
                    width: 150,
                    dataField: "outQty",
                    input: false,
                    inputType: ""
                },
                {
                    name: "已建入库数量",
                    width: 150,
                    dataField: "sendQty",
                    input: false,
                    inputType: ""
                },
                {
                    name: "本次入库数量",
                    width: 150,
                    dataField: "amount",
                    input: false,
                    inputType: ""
                },
                {
                    name: "备注",
                    width: 150,
                    dataField: "note",
                    input: true,
                    inputType: "note"
                }
                ]
            };
            $scope.newTbConf = {
                scrollWidth: 100,
                tableCol: [
                    {
                        name: "零件条码",
                        width: 150,
                        dataField: "barcode",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件编号",
                        width: 150,
                        dataField: "materiatsNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materiatsDes",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "数量",
                        width: 150,
                        dataField: "qty",
                        input: false,
                        inputType: ""
                    },
                ]
            };

            var btnPermissionCode = {
                handoverBillAdd: window.ActionCode.handoverBillAdd,
                handoverBillAddAuto: window.ActionCode.handoverBillAddAuto,
                handoverBillEdit: window.ActionCode.handoverBillEdit,
                handoverBillPrint: window.ActionCode.handoverBillPrint,
                handoverBillExport: window.ActionCode.handoverBillExport,
                handoverBillExportJckBatch: window.ActionCode.handoverBillExportJckBatch,
                handoverBillAbnormalIn: window.ActionCode.handoverBillAbnormalIn,
                handoverBillRemove: window.ActionCode.handoverBillRemove,
                handoverBillSend: window.ActionCode.handoverBillSend,
                handoverBillThreeDayPlan: window.ActionCode.handoverBillThreeDayPlan,
                handoverBillReceive: window.ActionCode.handoverBillReceive,
                handoverBillTJSC: window.ActionCode.handoverBillTJSC,
                handoverSaveDetailData: window.ActionCode.handoverSaveDetailData,
                handoverBillEncasementJck: window.ActionCode.handoverBillEncasementJck,
                handoverBillAddPackage: window.ActionCode.handoverBillAddPackage,
                handoverBillBarcodeBox: window.ActionCode.handoverBillBarcodeBox,
                handoverBillAudit: window.ActionCode.handoverBillAudit,
                handoverBillSyncJd: window.ActionCode.handoverBillSyncJd
            };

            $scope.btnPermission = {
                handoverBillAdd: true,
                handoverBillAddAuto: true,
                handoverBillEdit: true,
                handoverBillPrint: true,
                handoverBillExport: true,
                handoverBillExportJckBatch: true,
                handoverBillAbnormalIn: true,
                handoverBillRemove: true,
                handoverBillSend: true,
                handoverBillThreeDayPlan: true,
                handoverBillReceive: true,
                handoverBillTJSC: true,
                handoverSaveDetailData: true,
                handoverBillEncasementJck: true,
                handoverBillAddPackage: true,
                handoverBillBarcodeBox: true,
                handoverBillAudit: true,
                handoverBillSyncJd: true,
            };

            function setBtnPermission() {
                for (var key in btnPermissionCode) {
                    $scope.btnPermission[key] = UserContextService.CheckPermission([btnPermissionCode[key]]);
                }
            }

            $scope.setFixedWidth = function () {
                $scope.tbStyle = {
                    scrollLeft: {
                        left: $scope.tableConfig.fixedWidth + "px"
                    },
                    scrollLeftWidth: {
                        width: $scope.tableConfig.fixedWidth + "px"
                    },
                    billFixedWidth: {
                        left: $scope.addLeftTableConfig.fixedWidth + "px"
                    }
                };
            };


            $scope.changeTab = function (index) {
                $scope.activeFlag = [false, false, false, false];
                $scope.activeFlag[index] = true;
                $scope.submitted = false;
                switch (index) {
                    case 0:
                        $scope.markInfoForAdd = {};
                        $scope.materialsForAdd = [];
                        $scope.headFlagTwo = "";
                        $scope.headFlagThird = "";
                        initData();
                        break;
                    case 1:
                        $scope.headFlagTwo = "";
                        $scope.headFlagThird = "";
                        break;
                    case 2:
                        $scope.headFlagTwo = "detail";
                        break;
                    default:
                        $scope.headFlagTwo = "";
                        $scope.headFlagThird = "";
                        break;
                }
            };


            function initData() {
                $scope.sortObj = {};

                $scope.tabFlag = {};
                $scope.detailInfo = {
                    sex: 1,
                    locked: 0,
                    deliveryReceiptVO: {},
                    billList: [],
                    basicAttachmentList: []
                };
                $scope.abnormalObj = {
                    headerInfo: {},
                    detailList: []
                };
                $scope.innerOrder = {
                    item: null
                };
                $scope.selectedList = [];
                $scope.stepList.curStep = 0;
                $scope.dataSelected = {
                    role: {},
                    department: {}
                };
                $scope.billDetailDataList = [];
            }

            $scope.packageMaterialList = {
                barcodeList: [],
            };

            function getDataList(curPage) {

                var service = "device";
                var reqUrl = "/threeGuaFeeSettlement/list";
                var param = {};
                param.pageSize = $scope.pageInfo.pageSize;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }
                param.pageNum = $scope.pageInfo.curPage;
                param.filters = angular.copy($scope.condition);
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    if (resp.value.total > 0) {
                        angular.forEach(resp.value.list, function (item) {
                            item.createDate = $filter("YbDate")(item.createDate, 'yyyy-MM-dd HH:mm:ss');
                            item.auditStatusStr = $filter("ProgressStatus")(Number(item.auditStatus), "auditStatus");
                            item.checkStatusStr = $filter("ProgressStatus")(Number(item.checkStatus), "checkStatus");
                        });
                    }

                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }


            $scope.orderSelectAll = function () {
                angular.forEach($scope.orderDataList, function (item) {
                    if ($scope.orderMarkInfo.allChecked && !item.isChecked) {
                        item.isChecked = true;
                        $scope.selectedList.push(item);
                    }
                    if (!$scope.orderMarkInfo.allChecked && item.isChecked) {
                        item.isChecked = false;
                        for (var i = 0; i < $scope.selectedList.length; i++) {
                            if (item.salesOutBillNo == $scope.selectedList[i].salesOutBillNo) {
                                $scope.selectedList.splice(i, 1);
                                i--;
                            }
                        }
                    }
                })
            };
            $scope.orderSelectSingle = function (item) {
                if (item.isChecked) {
                    for (var i = 0; i < $scope.selectedList.length; i++) {
                        if ($scope.selectedList[i].salesOutBillNo === item.salesOutBillNo) {
                            return;
                        }
                    }
                    $scope.selectedList.push(item);
                    $scope.orderMarkInfo.allChecked = true;
                    angular.forEach($scope.orderDataList, function (item) {
                        if (!item.isChecked) {
                            $scope.orderMarkInfo.allChecked = false;
                        }
                    })
                } else {
                    $scope.orderMarkInfo.allChecked = false;
                    for (var i = 0; i < $scope.selectedList.length; i++) {
                        if ($scope.selectedList[i].salesOutBillNo == item.salesOutBillNo) {
                            $scope.selectedList.splice(i, 1);
                            i--;
                        }
                    }
                }
            };
            $scope.delSelected = function (index) {
                angular.forEach($scope.orderDataList, function (item) {
                    if (item.deliveryNo == $scope.selectedList[index].deliveryNo) {
                        item.isChecked = false;
                        $scope.orderMarkInfo.allChecked = false;
                    }
                });
                $scope.selectedList.splice(index, 1);
            };
            $scope.selectDealer = function () {
                var param = {
                    name: "申请单位",
                    type: "dealer"
                };
                ybWidget.SingleSelector(param).then(function (data) {
                    $scope.detailInfo.deliveryReceiptVO.dealerOrgName = data.companyName;
                    $scope.detailInfo.deliveryReceiptVO.customerId = data.id;
                    $scope.detailInfo.deliveryReceiptVO.dealerOrgId = data.dealerOrgId;
                })
            };
            $scope.nextStep = function () {

                if (!$scope.selectedList || $scope.selectedList.length == 0) {
                    ybWidget.ShowMessage('请选择出库单');
                    return;
                }
                let paramArr = $scope.selectedList.map(item => {
                    return item.salesOutBillNo
                });
                ybHttp.Get('device', '/threeGuaFeeSettlement/selectedOutsInfo', {
                    outNos: paramArr
                }).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    $scope.stepList.curStep = 1;
                    $scope.detailInfo = resp.value;
                })

            };




            $scope.prevStep = function () {
                $scope.stepList.curStep = 0;
            };

            $scope.sortObj = {};
            $scope.toSort = function (config, index) {
                if (!config[index].toSort) {
                    return;
                }
                $scope.sortObj.sortMethod = ybWidget.ToSort(config, index);
                $scope.sortObj.sortClumn = config[index].dataField;
                getBillList(1);
            };

            $scope.switchDataPicker = function (index) {
                $scope.datePickerFlag = [false, false, false, false, false, false];
                if (angular.isDefined(index)) {
                    $scope.datePickerFlag[index] = true;
                }
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };
            $scope.tdClick = function (item, fnType) {
                switch (fnType) {
                    case "viewDetail":
                        viewDetail(item);
                        break;
                    default:
                        break;
                }
            };
            $scope.selectRow = function (index) {
                $scope.markInfo.cueRow = index
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };


            $scope.reset = function () {
                $scope.condition = {};
                getDataList(1);
            };

            $scope.selectForAll = function () {
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    $scope.dataList[i].isChecked = $scope.markInfo.allChecked;
                }

            };

            function checkAll() {
                var selectAll = false;
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    if (!$scope.dataList[i].isChecked) {
                        selectAll = false;
                        break;
                    }
                    selectAll = true;
                }
                return selectAll;
            }

            $scope.selectSingle = function (item) {
                if (!item.isChecked) {
                    $scope.markInfo.allChecked = false;
                } else {
                    if (!checkAll()) {
                        $scope.markInfo.allChecked = false;
                    } else {
                        $scope.markInfo.allChecked = true;
                    }
                }

            };


            $scope.addData = function () {
                $scope.tabFlag = {
                    type: 0,
                    name: tabFlag[0]
                };
                $scope.orderCondition.billType = "1";//三包
                getBillList(1);
                $scope.changeTab(1);
            };


            //销售出库单列表
            function getBillList(curPage) {
                var service = "device";
                var reqUrl = "/threeGuaFeeSettlement/salesOuts";

                var param = {};
                param.pageSize = $scope.orderPageInfo.pageSize;
                if (!!curPage) {
                    $scope.orderPageInfo.curPage = curPage;
                }
                param.pageNum = $scope.orderPageInfo.curPage;
                param.filters = {
                    billType: $scope.orderCondition.billType,
                    salesOutBillNo: $scope.orderCondition.salesOutBillNo
                };
                $scope.orderDataList = [];
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }

                    if (!resp.value) {
                        resp.value = { list: [] }
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.createDate = $filter("YbDate")(item.createDate, "yyyy-MM-dd HH:mm:ss");
                    });
                    $scope.orderPageInfo.totalRows = resp.value.total;
                    $scope.orderPageInfo.totalPages = resp.value.pages;
                    $scope.orderDataList = resp.value.list;
                });
            }

            function viewGetBillList(curPage, billNos) {
                var service = "device";
                var reqUrl = "/threeGuaFeeSettlement/salesOuts";

                var param = {};
                param.pageSize = $scope.orderPageInfo.pageSize;
                if (!!curPage) {
                    $scope.orderPageInfo.curPage = curPage;
                }
                param.pageNum = $scope.orderPageInfo.curPage;
                param.filters = {
                    billType: $scope.orderCondition.billType,
                    salesOutBillNo: $scope.orderCondition.salesOutBillNo,
                    salesOutBillNos: billNos
                };
                $scope.orderDataList = [];
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }

                    if (!resp.value) {
                        resp.value = { list: [] }
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.createDate = $filter("YbDate")(item.createDate, "yyyy-MM-dd HH:mm:ss");
                    });
                    $scope.selectedList = resp.value.list;
                });
            }

            $scope.searchBill = function (curPage) {
                getBillList(curPage);
            };

            function viewDetail(item) {
                $scope.tabFlag = {
                    type: 2,
                    name: '详情'
                };
                // $scope.changeTab(1);
                queryBillOutDetails(item);
            }


            $scope.uniqueArr = function (arr1) {
                if (!arr1 || arr1.length == 0)
                    return arr1;
                const res = new Map()
                let singleArr = arr1.filter((item) => !res.has(item.salesOutBillNo) && res.set(item.salesOutBillNo, 1))
                if (singleArr && singleArr.length > 0) {
                    singleArr.map(function (items) {
                        return items.salesOutBillNo;
                    })

                }
                return singleArr;
            }
            $scope.goBack = function () {
                $scope.stepList.curStep = 0
            }
            $scope.editData = function (item) {
                $scope.tabFlag = {
                    type: 1,
                    name: tabFlag[1]
                };
                // $scope.changeTab(1);
                queryBillOutDetails(item);
            };

            function queryBillOutDetails(item) {
                var service = "device";
                var reqUrl = "/threeGuaFeeSettlement/item";
                var param = {};
                param.id = item.id;
                ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.detailInfo = resp.value;
                    $scope.changeTab(1);
                    $scope.selectedList.push(item);
                    $scope.stepList.curStep = 1;
                    // if ($scope.detailInfo != null
                    //     && $scope.detailInfo.links != null) {

                    //     const res = new Map()
                    //     let singleArr = $scope.detailInfo.links.filter((item) => !res.has(item.salesOutBillNo) && res.set(item.salesOutBillNo, 1))
                    //     if (singleArr && singleArr.length > 0) {
                    //         let outBillNos = singleArr.map(function (items) {
                    //             return items.salesOutBillNo;
                    //         })
                    //         viewGetBillList(1, outBillNos);
                    //     }
                    // }
                    if ($scope.detailInfo != null
                        && $scope.detailInfo.salesOutVOS != null) {
                        angular.forEach(resp.value.list, function (item) {
                            item.createDate = $filter("YbDate")(item.createDate, "yyyy-MM-dd HH:mm:ss");
                        });
                        $scope.selectedList = $scope.detailInfo.salesOutVOS;

                    } else {
                        $scope.selectedList = [];
                    }
                });
            }

            $scope.clickValue = false;
            $scope.saveData = function (isValid) {
                if (!isValid) {
                    $scope.submitted = true;
                    return;
                }
                var service = "device";
                var reqUrl = "/threeGuaFeeSettlement/save";
                //新增

                if ($scope.tabFlag.type === 0) {
                    let detail = $scope.detailInfo;
                    if (detail && detail.headInfo) {
                        detail.headInfo['settlementOrgId'] = null;
                        detail.headInfo['settlementOrgName'] = null;
                    }
                }
                let details=$scope.detailInfo['details'];
                if( (!details||details.length==0)||
                  (!$scope.selectedList||$scope.selectedList.length==0)){
                    ybWidget.ShowMessage('请选择出库单据', MESG_TYPE.Error);
                    return;
                }
                ybHttp.Post(service, reqUrl, $scope.detailInfo).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    $scope.changeTab(0);
                    $scope.selectedList = [];
                    getDataList();
                    $scope.markInfo.allChecked = false;
                    $scope.orderMarkInfo.allChecked = false;
                });
            };


            function reQueryMaterial() {
                if (!$scope.selectedList || $scope.selectedList.length == 0) {
                    $scope.detailInfo['details'] = [];
                    return false;
                }
                let paramArr = $scope.selectedList.map(item => {
                    return item.salesOutBillNo
                });
                ybHttp.Get('device', '/threeGuaFeeSettlement/selectedOutsInfo', {
                    outNos: paramArr
                }).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    $scope.detailInfo['details'] = resp.value ? resp.value['details'] : [];
                })
            };

            $scope.selectBill = function () {
                let params = {
                    selectedList: $scope.selectedList
                };

                ybWidget.GuaranteesFeeSettleSelector(params).then(function (data) {
                    if (!$scope.selectedList) {
                        $scope.selectedList = [];
                    }
                    $scope.selectedList.push(data);
                    reQueryMaterial();

                })
            };
            $scope.delBillOut = function (item, index) {
                ybWidget.ShowMessage("确定要删除吗？", MESG_TYPE.Ask).then(function () {
                    $scope.selectedList.splice(index, 1);
                    reQueryMaterial();
                })

            };




            $scope.selectAll = function (list, type) {
                angular.forEach(list, function (item) {
                    item.isChecked = $scope.markInfo["allChecked" + type];
                });

            };



            $scope.markInfoForAdd = {};
            $scope.materialsForAdd = [];



            $scope.auditMessage = {};

            function IsPC() {
                var userAgentInfo = navigator.userAgent.toLowerCase();
                var Agents = ["android", "iphone", "symbianos", "windows phone", "ipad", "ipod"];
                var flag = true;
                for (var v = 0; v < Agents.length; v++) {
                    if (userAgentInfo.indexOf(Agents[v]) > 0) {
                        flag = false;
                        break;
                    }
                }
                return flag;
            }
            $scope.isPC = false;

            (function () {
                $scope.isPC = IsPC();

                if ($state.params.orderNo) {
                    $scope.condition.purchaseNo = $state.params.orderNo
                }
                getDataList();
                $scope.setFixedWidth();
                UserContextService.SetBtnPermission(setBtnPermission);

            })();
        }]);
})(window, window.angular);
